package com.androidxmpp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;

import com.androidxmpp.config.PreferenceConstants;
import com.androidxmpp.util.PreferenceUtils;

/**
 * 初始化界面
 * @author chen_fulei
 *
 */
public class SplashActivity extends Activity{
	
	private final Activity activity = this;
	private Handler mHandler;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_splash);
		
		mHandler = new Handler();
		//判断是否记住密码
		String password = PreferenceUtils.getPrefString(this, PreferenceConstants.PASSWORD, "");
		if(TextUtils.isEmpty(password)){
			mHandler.postDelayed(gotoLoginAct, 3000);
		}else{
			mHandler.postDelayed(gotaoMainAct, 3000);
		}
	}

	//启动login
	private Runnable gotoLoginAct = new Runnable() {
		
		@Override
		public void run() {
			Intent intent = new Intent(activity, LoginActivity.class);
			startActivity(intent);
			finish();
		}
	};
	
	//记住密码，启动Main
	private Runnable gotaoMainAct = new Runnable() {
		
		@Override
		public void run() {
			Intent intent = new Intent(activity, MainActivity.class);
			startActivity(intent);
			overridePendingTransition(R.anim.enteralpha, R.anim.exitalpha);
			finish();
		}
	};
	
}
